local weikui = fk.CreateSkill {

  name = "joysp__weikui",

  tags = {  },

}



weikui:addEffect("active", {
  name = "joysp__weikui",
  anim_type = "offensive",
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(weikui.name, Player.HistoryPhase) == 0 and player.hp > 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:loseHp(player, 1, weikui.name)
    if player.dead or target:isKongcheng() then return end
    if not table.find(target:getCardIds("h"), function(id) return Fk:getCardById(id).trueName == "jink" end) then
      U.viewCards(player, target:getCardIds("h"), weikui.name)
      local mark = player:getTableMark( "joysp__weikui-turn")
      table.insert(mark, target.id)
      room:setPlayerMark(player, "joysp__weikui-turn", mark)
      room:useVirtualCard("slash", nil, player, target, weikui.name, true)
    else
      local id = room:askForCardChosen(player, target, { card_data = { { "$Hand", target:getCardIds("h") } } }, weikui.name,
      "#joysp__weikui-get:"..target.id)
      room:obtainCard(player,id,false,fk.ReasonPrey)
      if player:isWounded() then
        player.room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = weikui.name
          })
      end
    end
  end,
})

weikui:addEffect("distance", {
  name = "#joysp__weikui_distance",
  correct_func = function() return 0 end,
  fixed_func = function(self, from, to)
    local mark = from:getTableMark( "joysp__weikui-turn")
    if table.contains(mark, to.id) then
      return 1
    end
  end,
})

return weikui